<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Adminhtml
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Catalog product controller
 *
 * @category   Mage
 * @package    Mage_Adminhtml
 * @author      Magento Core Team <core@magentocommerce.com>
 */
require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
class TTT_Myfilter_Madminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{    
    public function productPrintAction()
    {
        $productIds = $this->getRequest()->getParam('product');
        if (!is_array($productIds)) {
            $this->_getSession()->addError($this->__('Please select product(s).'));
        } else {
            if (!empty($productIds)) {
                try {
                	$html ='<h1>'.Mage::helper('catalog')->__('Print Products').'</h1>';
	                $html .= '<table style="border-collapse:collapse;border:none;width:1000;margin:0 auto;text-align:center">';
	                $html .='<tr><th style="border:1px solid #ccc">Sku</th><th style="border:1px solid #ccc">Image</th><th style="border:1px solid #ccc">Name</th><th style="border:1px solid #ccc">Unit Price</th><th style="border:1px solid #ccc">Ref Cost</th><th style="border:1px solid #ccc">Shelf No</th><th style="border:1px solid #ccc">Weight</th><th style="border:1px solid #ccc">Qty</th><th style="border:1px solid #ccc">Status</th><th style="border:1px solid #ccc">Stock</th><th style="border:1px solid #ccc">Backorders</th></tr>';
                    foreach ($productIds as $productId) {
                        $product = Mage::getSingleton('catalog/product')->load($productId);
                        $html .='<tr>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getSku().'</td>';
	                    $image =  $product->getSmallImage()?'<img width="100" src="'.Mage::helper('catalog/image')->init($product, 'small_image',$product->getSmallImage())->resize(100).'" />':'';
	                    $html .='<td style="border:1px solid #ccc">'.$image.'</td>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getName().'</td>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getPrice().'</td>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getRefCost().'</td>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getShelfNo().'</td>';
	                    $html .='<td style="border:1px solid #ccc">'.$product->getWeight().'</td>';
	                    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
	                    $html .='<td style="border:1px solid #ccc">'.($stockItem->getQty()*1).'</td>';
	                      if ($product->getStatus()){ $status = 'Enabled';}else{ $status = 'Disabled';}
	                    $html .='<td style="border:1px solid #ccc">'.$status.'</td>';
	                    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
	                    if ($product->getIsInStock()){ $stock = 'In stock';}else{ $stock = 'Out of stock';}
	                        $html .='<td style="border:1px solid #ccc">'.$stock.'</td>';
	                    if($stockItem->getBackorders()==1){
	                        $backorders='Allow';
	                    }elseif($stockItem->getBackorders()==2){
	                        $backorders='Allow and Notify Customer';
	                    }else{
	                         $backorders='No';
	                    }
	                    $html .='<td style="border:1px solid #ccc">'.$backorders.'</td>';
	                    $html .='</tr>';
                    }
                    $html .= '</table>';
                    $html = '<div style="text-align:center">'.$html.'</div>';
        			$this->getResponse()->setBody($html);                   
                } catch (Exception $e) {
                    $this->_getSession()->addError($e->getMessage());
                }
            }
            else
            {
            	$this->getResponse()->setBody(Mage::helper('catalog')->__('Nothing to Printed'));  
            }
        }
    } 
}
